﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for clsCHINHANH
/// </summary>
public class clsCHINHANH
{
	public clsCHINHANH()
	{
		//
		// TODO: Add constructor logic here
		//
    }

    #region Select All
    public DataTable Select()
    {
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        try
        {
            dt = connect.GetSelectCommand("CHINHANH_Select", null);
        }
        catch 
        {
            dt = null;
        }
        return dt;
    }
    public DataTable GetBySessionMaCN(string F_MACN)
    {
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@F_MACN", F_MACN);
        try
        {
            dt = connect.GetSelectCommand("CHINHANH_Select_MaCN_in_GROUP", para);
        }
        catch
        {
            dt = null;
        }
        return dt;
    }
    public DataTable GetByF_MACN(string F_MACN)
    {
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@F_MACN", F_MACN);
        try
        {
            dt = connect.GetSelectCommand("CHINHANH_GetByF_MACN", para);
        }
        catch
        {
            dt = null;
        }
        return dt;
    }
    public string GetTencnByF_MACN(string F_MACN)
    {
        string rs = "";
        DataTable dt = new DataTable();
        dt = GetByF_MACN(F_MACN);
        if (dt.Rows.Count > 0)
        {
            rs = dt.Rows[0]["F_TENCN"].ToString();
        }
        return rs;
    }
    #endregion

    #region Insert
    public string Insert(string macn, string tencn, string diachi, string dienthoai, string fax, string Manager)
    {
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        SqlParameter[] para = new SqlParameter[6];
        para[0] = new SqlParameter("@macn", macn);
        para[1] = new SqlParameter("@tencn", tencn);
        para[2] = new SqlParameter("@diachi", diachi);
        para[3] = new SqlParameter("@dienthoai", dienthoai);
        para[4] = new SqlParameter("@fax", fax);
        para[5] = new SqlParameter("@Manager", Manager);

        try {
            connect.ExecuteQuery("CHINHANH_Insert", para);
            return "OK";
        }
        catch {
            return "ERR";
        }
    }
    #endregion

    #region Update
    public string Update(string macn, string tencn, string diachi, string dienthoai, string fax, string Manager)
    {
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        SqlParameter[] para = new SqlParameter[6];
        para[0] = new SqlParameter("@macn", macn);
        para[1] = new SqlParameter("@tencn", tencn);
        para[2] = new SqlParameter("@diachi", diachi);
        para[3] = new SqlParameter("@dienthoai", dienthoai);
        para[4] = new SqlParameter("@fax", fax);
        para[5] = new SqlParameter("@Manager", Manager);

        try
        {
            connect.ExecuteQuery("CHINHANH_Update", para);
            return "OK";
        }
        catch
        {
            return "ERR";
        }
    }
    #endregion

    #region Delete
    public string Delete(string macn)
    {
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@macn", macn);

        try
        {
            connect.ExecuteQuery("CHINHANH_Delete", para);
            return "OK";
        }
        catch {
            return "ERR";
        }
    }
    #endregion
}